<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Encrypt a PHP script with BLENC</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.blenc-encrypt" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">blenc_encrypt</h1>
  <p class="verinfo">(PECL blenc &gt;= 5)</p><p class="refpurpose"><span class="refname">blenc_encrypt</span> &mdash; <span class="dc-title">
   Encrypt a PHP script with BLENC
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.blenc-encrypt-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>blenc_encrypt</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$plaintext</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$encodedfile</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$encryption_key</code></span>
  ] ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Encrypt the <code class="parameter">plaintext</code> content and write it into <code class="parameter">encodedfile</code>
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.blenc-encrypt-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>

      <code class="parameter">plaintext</code>
     </dt>

     <dd>

      <p class="para">
       A source code to encrypt. Does not need to contain opening/closing PHP tags
      </p>
     </dd>

    
    
     <dt>

      <code class="parameter">encodedfile</code>
     </dt>

     <dd>

      <p class="para">
       The filename where BLENC will save the encoded source.
      </p>
     </dd>

    
    
     <dt>

      <code class="parameter">encryption_key</code>
     </dt>

     <dd>

      <p class="para">
       The key that BLENC will use to encrypt plaintext content. If not given
       BLENC will create a valid key.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.blenc-encrypt-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   BLENC will return the redistributable key that must be saved into key_file:
   the path of key_file is specified at runtime with the option blenc.key_file
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.blenc-encrypt-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-454">
    <p><strong>Example #1 <span class="function"><strong>blenc_encrypt()</strong></span> example </strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;read&nbsp;the&nbsp;PHP&nbsp;source&nbsp;code&nbsp;*/<br /></span><span style="color: #0000BB">$source_code&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">"my_source_to_protect.php"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;create&nbsp;the&nbsp;encrypted&nbsp;version&nbsp;*/<br /></span><span style="color: #0000BB">$redistributable_key&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">blenc_encrypt</span><span style="color: #007700">(</span><span style="color: #0000BB">$source_code</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_source_encoded.php"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;read&nbsp;which&nbsp;is&nbsp;the&nbsp;key_file&nbsp;*/<br /></span><span style="color: #0000BB">$key_file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'blenc.key_file'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;save&nbsp;the&nbsp;redistributable&nbsp;key&nbsp;*/<br /></span><span style="color: #0000BB">file_put_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">$key_file</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$redistributable_key</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">FILE_APPEND</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


</div></div></div></body></html>